/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package famtime.tm.kalender.model;

import java.io.Serializable;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;

/**
 *
 * @author Marius
 */
@Entity

public class Kalender implements Serializable {
    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
    
    @OneToMany(mappedBy = "parent", cascade=CascadeType.ALL, orphanRemoval=true)
    public List<Event> events = new LinkedList<Event>();
    
    @OneToOne
    public FamUser user;
    
       
    public Kalender() {
    }

    /**
     *
     * @param user
     */
    public Kalender(FamUser user) {        
        this.user = user;
    }    

    public List<Event> getEvents() {
        return events;
    }

    public void setEvents(List<Event> events) {
        this.events = events;
    }

    public void addEvent(Event e){
        System.out.println("THISSHIT");
        e.setParent(this);
        events.add(e);
    }
    
    public void removeEvent(Event e){
        e.setParent(null);
        events.remove(e);
    }
        
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Kalender)) {
            return false;
        }
        Kalender other = (Kalender) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "famtime.tm.kalender.Kalender[ id=" + id + " ]";
    }

    public void remove(Event e) {
        events.remove(e);
    }

    public void setUser(FamUser user) {
        this.user = user;
    }

    public static long getSerialVersionUID() {
        return serialVersionUID;
    }

    public FamUser getUser() {
        return user;
    }
    
}
